package com.client;

import java.util.ArrayList;
import java.util.List;

import com.client.forms.AdresseEditor;
import com.client.service.UserManagementService;
import com.client.service.UserManagementServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.shared.model.Assure;
import com.shared.utilitaire.Adresse;

public class PanelViewProfile extends Composite {
	
	private Label labelNom = new Label();
	private Label labelPrenom = new Label();
	private Label labelJour = new Label();
	private Label labelMois = new Label();
	private Label labelAnnee = new Label();
	private Label labelJourPermis = new Label();
	private Label labelMoisPermis = new Label();
	private Label labelAnneePermis = new Label();
	private Label labelViewPermisAnnule = new Label();
	//private RadioButton radioNon = new RadioButton("new name", "Non");
	private Label labelRecupJour = new Label();
	private Label labelRecupMois = new Label();
	private Label labelRecupAnnee = new Label();
	private Label labelMail = new Label();
	private Label labelTel = new Label();
	private Label labelMobile = new Label();
	private Label labelCivilite = new Label();
	Hyperlink linkAdresse2 = new Hyperlink("Adresse Supplementaire", "Adresse2");
	Hyperlink linkAdresse1 = new Hyperlink("Adresse Principale", "Adresse1");
	private final UserManagementServiceAsync userService = GWT.create(UserManagementService.class);
	private Assure assure = new Assure() ;
	boolean isViewAdresse1 = true;
	final AbsolutePanel panelAdresse = new AbsolutePanel();
	
	public PanelViewProfile(){
		// TODO Auto-generated constructor stub
	}
	
	@SuppressWarnings("deprecation")
	public AbsolutePanel createViewProfile(){
		
		AbsolutePanel panelViewProfile = new AbsolutePanel();
		

		//Adresse
		
		panelViewProfile.add(panelAdresse, 6, 265);
		panelAdresse.setSize("412px", "400px");
		final AdresseEditor adresseEdited = new AdresseEditor() ;

		
		final PanelViewAdresse panAdr = new PanelViewAdresse("Adresse Principale:");
	
		final PanelViewAdresse panAdr2 = new PanelViewAdresse("Adresse Supplementaire :");

		userService.getAssureCourant(new AsyncCallback<Assure>() {
			
			
			public void onSuccess(Assure result) {
				assure = result;
				labelCivilite.setText(assure.getCivilite()) ;
				labelNom.setText(assure.getNom());
				labelPrenom.setText(assure.getPrenom());
				labelJour.setText(assure.getDateNaissance().getJourString());
				labelMois.setText(assure.getDateNaissance().getMoisString());
				labelAnnee.setText(String.valueOf(assure.getDateNaissance().getAnnee()));
				labelJourPermis.setText(String.valueOf(assure.getDatePermis().getJourString()));
				labelMoisPermis.setText(assure.getDatePermis().getMoisString());
				labelAnneePermis.setText(String.valueOf(assure.getDatePermis().getAnnee()));
				
				
				if (assure.isPermisAnnule()){
					labelViewPermisAnnule.setText("Non") ;
					labelRecupJour.setText(assure.getDateReobtention().getJourString());
					labelRecupMois.setText(assure.getDateReobtention().getMoisString());
					labelRecupAnnee.setText(String.valueOf(assure.getDateReobtention().getAnnee()));}
				else{
					labelViewPermisAnnule.setText("Oui");
				}
				
				
				
				panAdr.getLabelViewCodePostal().setText(assure.getAdresse1().getCodePostal());
				panAdr.getLabelViewNumero().setText(assure.getAdresse1().getNumero());
				panAdr.getLabelViewPays().setText(assure.getAdresse1().getPays());
				panAdr.getLabelViewVille().setText(assure.getAdresse1().getVille());
				panAdr.getLabelViewVoie().setText(assure.getAdresse1().getNomVoie());
				panAdr.getLabelViewTypeVoie().setText(assure.getAdresse1().getTypeVoie());


				labelMail.setText(assure.getMail());
				labelTel.setText(assure.getNumeroTel());
				labelMobile.setText(assure.getNumeroMobile());
			};
			
			
			public void onFailure(Throwable caught) {
				Window.alert(caught.getMessage());
			}
			
		});
		

		panelViewProfile.setSize("674px", "600px");
		
		Label lblInscription = new Label("Visualisez votre profil");
		lblInscription.setStyleName("titre");
		panelViewProfile.add(lblInscription, 6, 6);
		
		Label labelCiviliteTitre = new Label("Civilite :");
		labelCiviliteTitre.addStyleName("gras");
		panelViewProfile.add(labelCiviliteTitre, 6, 56);
		
		panelViewProfile.add(labelCivilite, 95, 50);
		
		Label labelNomTitre = new Label("Nom :");
		labelNomTitre.addStyleName("gras");
		panelViewProfile.add(labelNomTitre, 6, 87);
		
		Label labelPrenomTitre = new Label("Prenom :");
		labelPrenomTitre.addStyleName("gras");
		panelViewProfile.add(labelPrenomTitre, 6, 119);
		
		panelViewProfile.add(labelNom, 95, 86);
		labelNom.setWidth("179px");
		
		panelViewProfile.add(labelPrenom, 95, 119);
		labelPrenom.setWidth("179px");
		
		Label labelNaissance = new Label("Date de naissance :");
		labelNaissance.addStyleName("gras");
		panelViewProfile.add(labelNaissance, 6, 154);
		
		panelViewProfile.add(labelJour, 167, 154);
		labelJour.setWidth("27px");
		
		Label slash = new Label("/");
		panelViewProfile.add(slash, 200, 154);
		slash.setSize("14px", "21px");
		
		panelViewProfile.add(labelMois, 210, 154);
		labelMois.setWidth("27px");
		
		Label slash2 = new Label("/");
		panelViewProfile.add(slash2, 243, 154);
		slash2.setSize("14px", "21px");
		
		panelViewProfile.add(labelAnnee, 253, 154);
		labelAnnee.setWidth("47px");
		
		Label labelDatePermis = new Label("Date d'obtention du permis :");
		labelDatePermis.addStyleName("gras");
		panelViewProfile.add(labelDatePermis, 6, 181);
		
		panelViewProfile.add(labelJourPermis, 220, 182);
		labelJourPermis.setWidth("27px");
		
		Label slash3 = new Label("/");
		panelViewProfile.add(slash3, 253, 182);
		slash3.setSize("14px", "21px");
		
		panelViewProfile.add(labelMoisPermis, 263, 182);
		labelMoisPermis.setWidth("27px");
		
		Label slash4 = new Label("/");
		panelViewProfile.add(slash4, 296, 182);
		slash4.setSize("14px", "21px");
		
		panelViewProfile.add(labelAnneePermis, 306, 182);
		labelAnneePermis.setWidth("47px");
		
		Label labelValide = new Label("Est-il valide ?");
		labelValide.addStyleName("gras");
		panelViewProfile.add(labelValide, 6, 208);
		
		panelViewProfile.add(labelViewPermisAnnule, 108, 208);
		
		Label labelRecup = new Label("Si non, quand le recuperez-vous ?");
		labelRecup.addStyleName("gras");
		panelViewProfile.add(labelRecup, 6, 232);
		
		
		panelViewProfile.add(labelRecupJour, 253, 230);
		labelRecupJour.setWidth("27px");
		
		Label slash5 = new Label("/");
		panelViewProfile.add(slash5, 286, 230);
		slash5.setSize("14px", "21px");
		
		panelViewProfile.add(labelRecupMois, 296, 230);
		labelRecupMois.setWidth("27px");
		
		Label slash6 = new Label("/");
		panelViewProfile.add(slash6, 329, 230);
		slash6.setSize("14px", "21px");
		
		panelViewProfile.add(labelRecupAnnee, 339, 230);
		labelRecupAnnee.setWidth("47px");
		
		panelAdresse.add(panAdr);

		panelAdresse.add(linkAdresse2, 256, 261);
		linkAdresse2.setSize("150px", "21px");
	

		linkAdresse2.addClickHandler(new ClickHandler() {
			
			
			public void onClick(ClickEvent event) {
				// TODO Auto-generated method stub

	            panelAdresse.clear();
	            panelAdresse.add(panAdr2);
	            
	            if (assure.getAdresse2() != null) {
	            panAdr2.getLabelViewCodePostal().setText(assure.getAdresse2().getCodePostal());
				panAdr2.getLabelViewNumero().setText(assure.getAdresse2().getNumero());
				panAdr2.getLabelViewPays().setText(assure.getAdresse2().getPays());
				panAdr2.getLabelViewVille().setText(assure.getAdresse2().getVille());
				panAdr2.getLabelViewVoie().setText(assure.getAdresse2().getNomVoie());
				panAdr2.getLabelViewTypeVoie().setText(assure.getAdresse1().getTypeVoie());
	            }
	            
	            panelAdresse.add(linkAdresse1, 256, 261);
				
			}
	 	        
			});
		
		linkAdresse1.addClickHandler(new ClickHandler() {
			
			
			public void onClick(ClickEvent event) {
				panelAdresse.clear();
        		panelAdresse.add(panAdr) ;
        		
        		panAdr.getLabelViewCodePostal().setText(assure.getAdresse1().getCodePostal());
  				panAdr.getLabelViewNumero().setText(assure.getAdresse1().getNumero());
  				panAdr.getLabelViewPays().setText(assure.getAdresse1().getPays());
  				panAdr.getLabelViewVille().setText(assure.getAdresse1().getVille());
  				panAdr.getLabelViewVoie().setText(assure.getAdresse1().getNomVoie());
  				panAdr.getLabelViewTypeVoie().setText(assure.getAdresse1().getTypeVoie());
  				
  				panelAdresse.add(linkAdresse2, 256, 261);
				
			}
		});
		
	
		Label labelMailTitre = new Label("Mail :");
		labelMailTitre.addStyleName("gras");
		panelViewProfile.add(labelMailTitre, 364, 56);
		
		panelViewProfile.add(labelMail, 406, 56);
		labelMail.setWidth("224px");
		
		Label labelTelTitre = new Label("Telephone :");
		labelTelTitre.addStyleName("gras");
		panelViewProfile.add(labelTelTitre, 316, 99);
		
		panelViewProfile.add(labelTel, 406, 99);
		
		Label labelMobileTitre = new Label("Mobile :");
		labelMobileTitre.addStyleName("gras");
		panelViewProfile.add(labelMobileTitre, 346, 136);
		
		panelViewProfile.add(labelMobile, 406, 135);

		
		return panelViewProfile;
		
	}
	

	
	
	
}